package com.moshang.mall.search.thread;

import java.util.concurrent.*;

/**
 * @Author xww
 * @Description //TODO
 * @Date 2020/9/14   10:55
 **/
public class ThreadTest {
    public static ExecutorService executor= Executors.newFixedThreadPool(10);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程:" + Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
            return i;
        }, executor).whenComplete((res,exception)->{
            System.out.println("结果是:"+res+"...异常是:"+exception);
        }).exceptionally(throwable -> {
            return 10;
        });
        System.out.println("main end ...."+completableFuture.get());
    }

}
